<?php
include_once "../header1.php";
?>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
require_once '../Login/databaseconnection.php';
if(!loggedin())
{
require_once '../index.php';
}
else
{	
if(isset($_POST['Search']))
{
$P_Id=$_POST['Pro_Id'];
	  
	   $year=$_POST['Year'];
	  
if($P_Id=="Select One"||$year=="Select One")
{
	$_SESSION['error']="Please select the Programme id and Year!";

}
  if($P_Id!="Select One"||$year!="Select One")
	   {
	if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $result=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND Year='$year' AND School_Id='$Own_School_Id'");
	   if(mysql_num_rows($result)==0)
   {
	   $_SESSION['errornorow']="Very sorry there is no result or you are not allowed to search this!";
   }
  }
  }
  else if($_SESSION['Access_Type']=="Administrator")
{
	  $result=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND Year='$year'");
	   if(mysql_num_rows($result)==0)
   {
	   $_SESSION['errornorow']="Very sorry there is no result,Please check your input and try again!";
   }
	   }
	   else
   {
   $_SESSION['errornotallo']="Sorry you are not allowed to do this!";
   }
	   }
	   }
?>
<?php

include_once "../header2.php";


?>
<?php
include_once "topmenu.php";
?>
<div class="left">
  
<div class="articles">
<form action="#" method="POST">
  <table width="964" border="0" class="tablefontv">
      <tr>
        <td height="18" colspan="7" align="left" scope="row">
          <?php
		if(isset($_POST['Search']))
{
	if($_SESSION['error']!=" ")
	{
		echo $_SESSION['error'];
		unset($_SESSION['error']);
	}
	if(isset($_SESSION['errornorow']))
	{
		echo $_SESSION['errornorow'];
		unset($_SESSION['errornorow']);
	}
}
		?>
        </td>
        </tr>
      <tr>
        <td width="63" rowspan="2" align="left" scope="row" bgcolor="#6AB5FF">Search by</td>
      <td width="77" height="22" align="left" scope="row" bgcolor="#6AB5FF">Programme Id</td>
      <th width="8" align="left" scope="row" bgcolor="#6AB5FF">:-</th>
      <td width="78" bgcolor="#999999"><select name="Pro_Id" id="select">
	   <?php
	  
	  if(isset($_POST['Search']))
	  {
	echo '<option value="'.$P_Id.'">'.$P_Id.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
   
      <?php
	  $pro=mysql_query("SELECT DISTINCT(Programme_Id) FROM programmes");
	  
  while($row=mysql_fetch_array($pro))
  {
	  $p_id=$row['Programme_Id'];

	  echo '<option value="'.$p_id.'">'.$p_id.'</option>';
  }
	  ?>
     
      </select></td>
      <td width="46" rowspan="2" bgcolor="#6AB5FF">Other Way:</td>
      <td width="223" rowspan="2" bgcolor="#999999"><table width="225" border="1">
          <tr>
            <td width="215"><input type="text" name="textfield3" />
              
              <input name="SearchOther" align="middle" type="submit" value="Search" />
              </td>
            </tr>
        </table></td>
      <?php
	  if(isset($_POST['Search']))
	 {
      echo '<th width="213">';
	  echo "Total number of Students:";
	  echo '</th>';
      echo '<td width="129">';
	   
	 $Pro_Id=$_POST['Pro_Id'];
$Year=$_POST['Year'];
$ques=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$Pro_Id' AND Year='$Year'");
	  $st_no=0;
	 while($row=mysql_fetch_array($ques))
	 {
	 $st_no=$st_no+$row['No_Of_Students'];
	 }
	   
	  if($st_no!=0){echo "<input type='text' name='No_Students' value='$st_no' readonly='readonly'/>";}
	  else
	  {echo "<input type='text' name='No_Students' readonly='readonly'/>";}
	 }
	 echo '</td>';
	  ?>
      </tr>
    <tr>
      <td height="28" align="left" scope="row" bgcolor="#6AB5FF">Year</td>
      <th width="8" align="left" scope="row" bgcolor="#6AB5FF">:-</th>
      <td bgcolor="#999999"><select name="Year" id="Year">
        <?php
	  
	  if(isset($_POST['Search']))
	  {
	echo '<option value="'.$year.'">'.$year.'</option>';
	  }
	  else
	  {
	  echo '<option value="Select One">Select One</option>';
	  }
	  ?>
        <?php
	  $pro=mysql_query("SELECT DISTINCT(Year) FROM programmes");
	  
  while($row=mysql_fetch_array($pro))
  {
	 $year=$row['Year'];

	  echo '<option value="'.$year.'">'.$year.'</option>';
  }
	  ?>
      </select></td>
       <?php
	  if(isset($_POST['Search']))
	 {
      echo '<th height="24" align="left" scope="row" width="213">';
	  echo "Total number of Teachers in training:";
	  echo '</th>';
      echo '<td height="24">'; 
	    
	 $Pro_Id=$_POST['Pro_Id'];
$Year=$_POST['Year'];
$quett=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$Pro_Id' AND Year='$Year'");
	  $t_no=0;
	 while($row=mysql_fetch_array($quett))
	 {
	 $t_no=$t_no+$row['Teachers_In_Training'];
	 }
	  if($t_no!=0){echo "<input type='text' name='No_Teachers' value='$t_no' readonly='readonly'/>";}
	  else
	  {echo "<input type='text' name='No_Teachers' readonly='readonly'/>";}
	 }echo '</td>';
	  ?>
      </tr>
    <tr>
      <th height="34" colspan="6" align="left" bgcolor="#6AB5FF" scope="row"><p><a href="SearchPro.php" class="reset">Reset |</a>
        <input name="Search" align="middle" type="submit" value="Search" />
        </p>
        
        
      </th>
       <?php
	  if(isset($_POST['Search']))
	 {
      echo '<th height="24" align="left" scope="row" width="213">';
	  echo "Total number of trained Teachers:";
	  echo '</th>';
      echo '<td height="24">'; 
	    
	 $Pro_Id=$_POST['Pro_Id'];
$Year=$_POST['Year'];
$quet=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$Pro_Id' AND Year='$Year'");
	  $tr_no=0;
	 while($row=mysql_fetch_array($quet))
	 {
	 $tr_no=$tr_no+$row['Trained_Teachers'];
	 }
	  if($tr_no!=0){echo "<input type='text' name='No_Teachers' value='$tr_no' readonly='readonly'/>";}
	  else
	  {echo "<input type='text' name='No_Teachers' readonly='readonly'/>";}
	 }echo '</td>';
	  ?><td width="439"></td>
      </tr>
  </table>
  </form>
  <?php
  
if(isset($_POST['Search']))
{
	
	 $P_Id=$_POST['Pro_Id'];

	   $year=$_POST['Year'];

if($P_Id!="Select One"&&$year!="Select One")
{
 if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $result=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND Year='$year' AND School_Id='$Own_School_Id'");
if(mysql_num_rows($result)!=0)
   {

echo '<table width="957" border="1">

<tr>
<td width="94">Programme Id</td>
<td width="48">Year</td>
<td width="46">School Id</td>
<td width="130">Programme Name</td>
<td width="100">Number of students</td>
<td width="158">Number of teachers in training</td>
<td width="137">Number of trained teachers</td>
<td width="93">Availability of books</td>
<td width="159">Number of teachers guides</td>
</tr>';
 
  while($row=mysql_fetch_array($result))
  {
    echo '<tr>';
    echo '<td width="94">'.$row['Programme_Id'].'</td>';
    echo '<td width="48">'.$row['Year'].'</td>';
    echo '<td width="46">'.$row['School_Id'].'</td>';
    echo '<td width="130">'.$row['Programme_Name'].'</td>';
    echo '<td width="100">'.$row['No_Of_Students'].'</td>';
    echo '<td width="158">'.$row['Teachers_In_Training'].'</td>';
    echo '<td width="137">'.$row['Trained_Teachers'].'</td>';
    echo '<td width="93">'.$row['Availability_Books'].'</td>';
    echo '<td width="159">'.$row['Availability_Tguides'].'</td>';
  echo '</tr>';
  }
   echo '</table>';

}
   }
   }
  else if($_SESSION['Access_Type']=="Administrator")
{
$result=mysql_query("SELECT * FROM programmes WHERE Programme_Id='$P_Id' AND Year='$year'");
if(mysql_num_rows($result)!=0)
   {

echo '<table width="957" border="1">

<tr>
<td width="94">Programme Id</td>
<td width="48">Year</td>
<td width="46">School Id</td>
<td width="130">Programme Name</td>
<td width="100">Number of students</td>
<td width="158">Number of teachers in training</td>
<td width="137">Number of trained teachers</td>
<td width="93">Availability of books</td>
<td width="159">Number of teachers guides</td>
</tr>';
 
  while($row=mysql_fetch_array($result))
  {
    echo '<tr>';
    echo '<td width="94">'.$row['Programme_Id'].'</td>';
    echo '<td width="48">'.$row['Year'].'</td>';
    echo '<td width="46">'.$row['School_Id'].'</td>';
    echo '<td width="130">'.$row['Programme_Name'].'</td>';
    echo '<td width="100">'.$row['No_Of_Students'].'</td>';
    echo '<td width="158">'.$row['Teachers_In_Training'].'</td>';
    echo '<td width="137">'.$row['Trained_Teachers'].'</td>';
    echo '<td width="93">'.$row['Availability_Books'].'</td>';
    echo '<td width="159">'.$row['Availability_Tguides'].'</td>';
  echo '</tr>';
  }
   echo '</table>';

}
  }
  }
  }
  ?>
</div>
</div>

<div class="rightmenu"> 
<?php
include_once "menu.php";
?>
<?php
include_once "../footer.php";
?>
<?php

}
?>
</body>
</html>